package blog.service.impl;

import blog.dao.PartnerDao;
import blog.pojo.Partner;
import blog.service.PartnerService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class PartnerServiceImpl implements PartnerService {

    @Autowired
    private PartnerDao partnerDao;

    @Override
    public Page<Partner> getPage(Page page, Partner partner, String keywords) throws Exception {
        if (page == null) return null;
        QueryWrapper<Partner> queryWrapper = new QueryWrapper<>(partner)
                .ne("isuse", 2);
        if (keywords != null) {
            queryWrapper.like("name", keywords);
        }
        return partnerDao.selectPage(page, queryWrapper);
    }

    @Override
    public Partner getInfo(Integer id) throws Exception {
        return partnerDao.selectOne(new QueryWrapper<Partner>().setEntity(new Partner().setId(id)));
    }

    @Override
    public Boolean update(Partner partner) throws Exception {
        return partnerDao.updateById(partner) > 0;
    }

    @Override
    public Boolean insert(Partner partner) throws Exception {
       return partnerDao.insert(partner) > 0;
    }
}
